﻿using System;
#if SILVERLIGHT
using System.Windows.Graphics;
using System.Windows.Controls;
#endif
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SoSlam.Common.Communication;
using SoTools.Communicator;


namespace SoSlam.Common.ClientLogic
{
	public class SoSlamGame : Game
	{
		private GraphicsDeviceManager _graphics;
		private SpriteBatch _spriteBatch;
        //private SoSlam.Common.ClientLogic.ScreenManager.ScreenManager _screenManager;

#if SILVERLIGHT
		public SoSlamGame(DrawingSurface drawingSurface)
			: base(drawingSurface)
		{
			_graphics = GraphicsDeviceManager.Current;
		}
#else
		public SoSlamGame()
		{
			_graphics = new GraphicsDeviceManager(this);
            
#if WINDOWS_PHONE
            _graphics.IsFullScreen = true;
            TargetElapsedTime = TimeSpan.FromTicks(333333);
#else
            TargetElapsedTime = TimeSpan.FromSeconds((double)1 / 40);
#endif

            Content.RootDirectory = "Content";
			IsFixedTimeStep = true;
			IsMouseVisible = true;
			Window.AllowUserResizing = true;
			Window.Title = "SoSlam";
		}
#endif

		protected override void Initialize()
		{
			var communicator = new Communicator();
			communicator.Listen();
			Services.AddService(typeof(Communicator), communicator);

			var world = new World(this);
			Components.Add(world);

			base.Initialize();
		}

		protected override void LoadContent()
		{
			_spriteBatch = new SpriteBatch(GraphicsDevice);
		}

		protected override void UnloadContent()
		{

		}

		protected override void Update(GameTime updateGameTime)
		{
			base.Update(updateGameTime);
		}

		protected override void Draw(GameTime gameTime)
		{
			GraphicsDevice.Clear(Color.FromNonPremultiplied(135, 206, 250, 255));

			base.Draw(gameTime);
		}
	}
}